package com.bang.framework.base.response;


import com.bang.framework.base.enums.ResultCode;

/**
 * @Desc: BaseController
 * @Author: <BANG>
 * @Date: 2019/12/4 0004 上午 11:21
 */
public class BaseController {

    /**
     * 返回成功
     *
     * @return
     */
    protected <T> Result resultSuccess() {
        return new Result().setCode(ResultCode.SUCCESS);
    }

    /**
     * 返回成功-携带消息
     *
     * @param msg
     * @return
     */
    protected <T> Result resultSuccess(String msg) {
        return new Result().setCode(ResultCode.SUCCESS).setMessage(msg);
    }

    /**
     * 返回成功-携带数据
     *
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultSuccess(T data) {
        return new Result().setCode(ResultCode.SUCCESS).setData(data);
    }

    /**
     * 返回成功-携带消息和数据
     *
     * @param msg
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultSuccess(String msg, T data) {
        return new Result().setCode(ResultCode.SUCCESS).setMessage(msg).setData(data);
    }

    /**
     * 返回失败
     *
     * @return
     */
    protected <T> Result resultFail() {
        return new Result().setCode(ResultCode.FAIL);
    }

    /**
     * 返回失败-携带消息
     *
     * @return
     */
    protected <T> Result resultFail(String msg) {
        return new Result().setMessage(msg).setCode(ResultCode.FAIL);
    }

    /**
     * 返回失败-携带数据
     *
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultFail(T data) {
        return new Result().setCode(ResultCode.FAIL).setData(data);
    }

    /**
     * 返回失败-携带数据和数据
     *
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultFail(String msg, T data) {
        return new Result().setCode(ResultCode.FAIL).setMessage(msg).setData(data);
    }

    /**
     * 参数错误
     *
     * @return
     */
    protected Result resultParamFail() {
        return new Result().setCode(ResultCode.FAIL_PARAM);
    }

    /**
     * 参数错误
     *
     * @return
     */
    protected Result resultParamFail(String msg) {
        return new Result().setCode(ResultCode.FAIL_PARAM).setMessage(msg);
    }

    /**
     * 返回失败-携带数据和数据
     *
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultParamFail(String msg, T data) {
        return new Result().setCode(ResultCode.FAIL_PARAM).setMessage(msg).setData(data);
    }

    /**
     * 返回失败-系统异常
     *
     * @param data
     * @param <T>
     * @return
     */
    protected <T> Result resultSysFail(String msg, T data) {
        return new Result().setCode(ResultCode.INTERNAL_SERVER_ERROR).setMessage(msg).setData(data);
    }
}
